package wechat.app.corp.domain;

import com.google.common.base.Objects;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import wechat.app.WCCorpApplication;
import wechat.app.WXCorpAppFactory;
import wechat.base.snd.WCNews;
import wechat.base.snd.WCNewsItem;

@SuppressWarnings("all")
public class EngineerNotificationCorpWeChat {
  private static Logger logger = Logger.getLogger("EngineerNotificationCorpWeChat");
  
  private static String CALLBACK_SERVER_URL = "http://210.22.183.30:8090";
  
  public static String generateNotificationDetailsUrl(final String id) {
    return ((EngineerNotificationCorpWeChat.CALLBACK_SERVER_URL + "/notificationdetail?notificationId=") + id);
  }
  
  public static void sendNormalNotification(final WCCorpApplication app, final Iterable<String> users, final String title, final String body, final String id) {
    final Procedure1<String> _function = new Procedure1<String>() {
      public void apply(final String it) {
        InputOutput.<String>println(("==========>send to " + it));
      }
    };
    IterableExtensions.<String>forEach(users, _function);
    WCNews _createNews = app.createNews();
    final Procedure1<WCNews> _function_1 = new Procedure1<WCNews>() {
      public void apply(final WCNews it) {
        WCNewsItem _withItem = it.withItem(title);
        final Procedure1<WCNewsItem> _function = new Procedure1<WCNewsItem>() {
          public void apply(final WCNewsItem it) {
            String _generateNotificationDetailsUrl = EngineerNotificationCorpWeChat.generateNotificationDetailsUrl(id);
            it.setUrl(_generateNotificationDetailsUrl);
          }
        };
        ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem, _function);
        WCNewsItem _withItem_1 = it.withItem(body);
        final Procedure1<WCNewsItem> _function_1 = new Procedure1<WCNewsItem>() {
          public void apply(final WCNewsItem it) {
            String _generateNotificationDetailsUrl = EngineerNotificationCorpWeChat.generateNotificationDetailsUrl(id);
            it.setUrl(_generateNotificationDetailsUrl);
          }
        };
        ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem_1, _function_1);
        it.send2Users(users);
      }
    };
    ObjectExtensions.<WCNews>operator_doubleArrow(_createNews, _function_1);
  }
  
  public static void respondMenuEvent(final String wechatid, final String state) {
    WCCorpApplication _defaultCorpApp = WXCorpAppFactory.getDefaultCorpApp();
    final Procedure1<WCCorpApplication> _function = new Procedure1<WCCorpApplication>() {
      public void apply(final WCCorpApplication it) {
        WCNews _createNews = it.createNews();
        final Procedure1<WCNews> _function = new Procedure1<WCNews>() {
          public void apply(final WCNews it) {
            boolean _equals = Objects.equal(state, "100");
            if (_equals) {
              WCNewsItem _withItem = it.withItem("工单列表");
              final Procedure1<WCNewsItem> _function = new Procedure1<WCNewsItem>() {
                public void apply(final WCNewsItem it) {
                  it.setUrl((("http://210.22.183.30:8090/mylist?wechatid=" + wechatid) + "&state=100"));
                }
              };
              ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem, _function);
            } else {
              boolean _equals_1 = Objects.equal(state, "101");
              if (_equals_1) {
                WCNewsItem _withItem_1 = it.withItem("通知列表");
                final Procedure1<WCNewsItem> _function_1 = new Procedure1<WCNewsItem>() {
                  public void apply(final WCNewsItem it) {
                    it.setUrl((("http://210.22.183.30:8090/mylist?wechatid=" + wechatid) + "&state=101"));
                  }
                };
                ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem_1, _function_1);
              }
            }
            ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(wechatid);
            it.send2Users(_newArrayList);
          }
        };
        ObjectExtensions.<WCNews>operator_doubleArrow(_createNews, _function);
      }
    };
    ObjectExtensions.<WCCorpApplication>operator_doubleArrow(_defaultCorpApp, _function);
  }
}
